<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="处理意见" @ok="handleSubmit">
    <BasicForm @register="registerForm">
    </BasicForm>
  </BasicModal>
</template>
<script lang="ts" setup>
import { ref } from 'vue';

import { HandleModalFormSchema } from './fire.data';
import { BasicForm, useForm } from '@/components/Form';
import { BasicModal, useModalInner } from '@/components/Modal';

import { alarmRecordProcess } from '@/api/collection/alarm'

defineOptions({ name: 'HandleModal' });

const emit = defineEmits(['success', 'register']);

const rowId = ref('');

const [registerForm, { resetFields, validate }] = useForm({
  labelWidth: 100,
  baseColProps: { span: 24 },
  schemas: HandleModalFormSchema,
  showActionButtonGroup: false,
  actionColOptions: {
    span: 23,
  },
});

const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
  rowId.value = data.record.id;
  resetFields();
  setModalProps({ confirmLoading: false });
});

async function handleSubmit() {
  try {
    const values = await validate();

    setModalProps({ confirmLoading: true });
    const params = { ...values, alarmRecordId: rowId.value }
    await alarmRecordProcess(params)

    closeModal();
    emit('success', { values: { ...values, alarmRecordId: rowId.value } });
  } finally {
    setModalProps({ confirmLoading: false });
  }
}
</script>
<style scoped></style>
